import { Global, Module } from '@nestjs/common';
import { DbService } from './db.service';
import { MemberRepositoryModule } from '@app/db/common/member-repository/member-repository.module';
import { MerchantRepositoryModule } from '@app/db/merchant-repository/merchant-repository.module';
import { MenuRepositoryModule } from '@app/db/common/menu-repository/menu-repository.module';
import { RoleRepositoryModule } from '@app/db/common/role-repository/role-repository.module';
import { DictionaryCategoryRepositoryModule } from '@app/db/common/dictionary-category-repository/dictionary-category-repository.module';
import { DictionaryItemRepositoryModule } from '@app/db/common/dictionary-item-repository/dictionary-item-repository.module';
import { DeviceTypeRepositoryModule } from '@app/db/device-type-repository/device-type-repository.module';
import { DeviceRepositoryModule } from '@app/db/device-repository/device-repository.module';
import { DeviceParamsFieldRepositoryModule } from '@app/db/device-params-field-repository/device-params-field-repository.module';
import { DeviceParamsRepositoryModule } from '@app/db/device-params-repository/device-params-repository.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigureModule, ConfigureService } from '@app/configure';

import { RechargeOptionRepositoryModule } from '@app/db/recharge-option-repository/recharge-option-repository.module';
import { SysConfigRepositoryModule } from '@app/db/common/sys-config-repository/sys-config-repository.module';
import { WaterBillsRepositoryModule } from '@app/db/water-bills-repository/water-bills-repository.module';
import { WaterTestRepositoryModule } from '@app/db/water-test-repository/water-test-repository.module';
import { UserRepositoryModule } from '@app/db/user-repository/user-repository.module';
import { RechargeOrderRepositoryModule } from '@app/db/recharge-order-repository/recharge-order-repository.module';
import { UserWalletLogRepositoryModule } from '@app/db/user-wallet-log-repository/user-wallet-log-repository.module';

@Global()
@Module({
  imports : [
    TypeOrmModule.forRootAsync({
      imports : [ConfigureModule],
      inject : [ConfigureService],
      useFactory : (config:ConfigureService) => {

       
        
        return {
          ...config.get('db')
        }
      },
    
      // dataSourceFactory: async (options) => {
      // 	const dataSource = await new DataSource(options).initialize();
      // 	return dataSource;
      // },
    }),
    MemberRepositoryModule,
    MenuRepositoryModule,
    RoleRepositoryModule,
    DictionaryCategoryRepositoryModule,
    DictionaryItemRepositoryModule,
    SysConfigRepositoryModule,

    MerchantRepositoryModule,
    DeviceTypeRepositoryModule,
    DeviceRepositoryModule,
    DeviceParamsFieldRepositoryModule,
    DeviceParamsRepositoryModule,
    WaterBillsRepositoryModule,
    WaterTestRepositoryModule,
    UserRepositoryModule,

    RechargeOptionRepositoryModule,
    RechargeOrderRepositoryModule,
    UserWalletLogRepositoryModule,
    
  ],
  providers: [DbService],
  exports : [DbService]
})
export class DbModule {}
